//
// Created by zhouwd on 2019/7/5.
//

#ifndef IPTVSETTING_MEDIA_RECORD_H
#define IPTVSETTING_MEDIA_RECORD_H
#include <cstdlib>
#include <cstring>
#include <media/NdkMediaCodec.h>
#include <media/NdkMediaMuxer.h>
#include <android/log.h>
#include <time.h>
#include "base-thread.h"

#define LOG_TAG "CAMERA-RENDER"
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define TOTAL_TRACK 2

typedef class _MEDIA_RECORD : Thread {
private:
    AMediaMuxer *muxer;
    AMediaCodec *audioCodec,*videoCodec;
    bool status = false;
    ssize_t audioTrack, videoTrack;
    int trackNum = 0;
    int64_t voiceRenderStart = -1;
    int64_t videoRenderStart = -1;
    int64_t audioPresentationTimeUs, videoPresentationTimeUs;
public:
    int init(int fd);
    void drainVideoEncoder();
    void drainAudioEncoder();
    void run();
    int encodeVideoData(char *data, size_t buf_size);
    int encodeAudioData(char *data, size_t buf_size);
    int startRecord();
    int stopRecord();
    int release();
}MediaRecord;


#endif //IPTVSETTING_MEDIA_RECORD_H
